//
// Created by Zhangwj on 2023/9/27.
//

#include "RelExpNode.h"

std::unique_ptr<RelExpNode> RelExpNode::RelExpParser(Parser &parser) {
    //RelExp → AddExp | RelExp ('<' | '>' | '<=' | '>=') AddExp
    //改写为 RelExp -> AddExp { ('<' | '>' | '<=' | '>=') AddExp }
    std::unique_ptr<RelExpNode> relExpNode = std::make_unique<RelExpNode>();
    relExpNode->AddExps.push_back(AddExpNode::AddExpParser(parser));
    while (parser.getLexType(0) == LexType::LSS || parser.getLexType(0) == LexType::LEQ ||
           parser.getLexType(0) == LexType::GRE || parser.getLexType(0) == LexType::GEQ) {
        relExpNode->Ops.push_back(parser.getLexType(0));
        parser.next();
        relExpNode->AddExps.push_back(AddExpNode::AddExpParser(parser));
    }
    return relExpNode;
}
